#!/bin/bash
# Place the compiled Agent binary, config file, and alibabacloud-kms-agent.service file into current directory.

# The execution directory of the Agent on the VM
RunDir=/usr/local/alibabacloudkmsagent
# Agent binary and configuration file
Agent=alibabacloud-kms-agent
AgentConfig=config.toml
# systemd service file directory
SystemdFilesDir=/etc/systemd/system


if [ `id -u` -ne 0 ]; then
    echo "This script must be run as root" >&2
    exit 1
fi


# Copy the binary and configuration file to the execution directory
install -D -T -m 755 ${Agent} ${RunDir}/${Agent}
install -D -T -m 755 ${AgentConfig} ${RunDir}/${AgentConfig}

# Set up systemd to manage the process
install -T -m 755 ${Agent}.service ${SystemdFilesDir}/${Agent}.service

systemctl enable ${Agent}
systemctl start ${Agent}

exit 0
